﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_初级教程
{
    public class 枚举类型
    {

        //其实每一个枚举值，都会对应一个整形值，
        //定义枚举类型
        enum Sex
        { 
            Man,
            Woman
        }

        //定义枚举类型
        enum OrderState //枚举类型都是继承于Enum类
        { 
            /// <summary>
            /// 待支付
            /// </summary>
            WaitPay,
            Pay,
            WaitSend,
            WaitReceive,
            Receive,
            Cancel,
            WaitComment,
            Finish
        }

        //可以用中文
        /// <summary>
        /// 资产审核状态
        /// </summary>
        public enum PropertyStatu
        {
            已驳回 = 0,//这是默认值写法
            待审核 = 1,
            已通过 = 2
        }

        /// <summary>
        /// 使用枚举
        /// </summary>
        public void test()
        {
            //声明枚举变量
            Sex sex = Sex.Man;
            if (sex == Sex.Man)
            {
                Console.WriteLine("男性");
            }
            else
            {
                Console.WriteLine("女性");
            }
        }

        public void test2()
        {
            OrderState state = OrderState.Finish;
            //枚举类型转化为int类型
            int intState = (int)state;

            //int转化为枚举
            int a = 3;
            OrderState state1 = (OrderState)a;

            //string转化为枚举
            string str = "Finish";
            OrderState state3 = (OrderState)Enum.Parse(typeof(OrderState), str);
            OrderState state4 = Enum.Parse<OrderState>(str);//这个泛型方法也行

            PropertyStatu propertyStatu = PropertyStatu.已通过;

            //枚举转化成字符穿
            string str3 = state3.ToString();

        }
    }
}
